<template>
	<view class="">
		<view class="score-item fboxCol Ycenter">
			<view class="hd w690 fboxRow Ycenter font24 color-36363A">
				<view class="title fboxRow Ycenter flex1">
					<view class="dot" :class="type == 1 ? 'bg-00C15D' : type == 2 ? 'bg-3480FF' : 'bg-FFBC44'"></view>
					{{type == 2 ? '期望成绩' : '高考成绩'}}
				</view>
				<view class="right">
					<view style="color:#E85531" v-if="type == 2">请录入原始成绩，未赋分</view>
				</view>
			</view>
			<view class="bd w690 fboxWrap">
				<view class="score-tag fboxCol" v-for="(bItem, BIndex) in scoreList.scoreInfos" :key="BIndex">
					<view class="tit fboxRow Ycenter Xcenter font24 color-9899A1">
						{{bItem.subjectName}}
					</view>
					<view class="con fboxRow Ycenter Xcenter">
						<stepper :info="bItem" @change="stepChange" />
					</view>
				</view>
			</view>
			<view class="ft w690 fboxRow Ycenter font22">
				<view class="time flex1 color-9899A1" @tap="selectedSubjects">修改选科</view>
				<view class="right">
					<text style="margin-right: 30rpx;" @tap="cancelTap" class="color-9899A1">取消</text>
					<text class="color-00C15D" @tap="saveTap">保存</text>
				</view>
			</view>
		</view>
		<score-subjects :show.sync="popupShow" :scoreList="scoreList" @on-subjects="subjectDefine" />
	</view>
</template>

<script>
	import {
		myScoreUpdate,
		scoreEntering,
		isAnalysis
	} from '@/api/bks.volunteer.js'
	import {
		getBksInfo
	} from '@/static/js/bks.common.js'
	import stepper from './stepper.vue'
	import ScoreSubjects from './score-subjects.vue'
	export default {
		components: {stepper, ScoreSubjects},
		props: {
			scoreList: {
				type: Object,
				default: () => {
					return {
						// "scoreInfos": [],
						// examName: '三诊成绩',
						// time: '2021.04.28 14:30:20'
					}
				}
			},
			type: {
				type: [String, Number],
				default: 1
			},
			edit: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				loading: false,
				showVipDialog: false,
				popupShow: false
			}
		},
		methods: {
			stepChange: function(e) {
				this.scoreList.scoreInfos.filter((item, index) => {
					if (item.subjectName == e.name) {
						this.scoreList.scoreInfos[index].subjectScore = e.value
					}
				})
			},
			selectedSubjects() {
				this.popupShow = true
			},
			// 取消
			cancelTap() {
				this.$emit('onCancel', {
					type: this.type
				})
			},

			// 保存
			saveTap() {
				const reqData = {
					"id": this.scoreList.examIdKd ? '' : this.scoreList.id,
					"type": this.type
				}
				this.scoreList.scoreInfos.filter(item => {
					if (reqData.type == 3 && item.subId) {
						reqData[item.subId] = item.subjectScore || 0
					} else {
						reqData[item.id] = item.subjectScore || 0
					}
				})
				myScoreUpdate(reqData).then(res => {
					const id = res.data
					if (id) {
						isAnalysis({
							type: this.type
						}).then(res => {
							if (res.data) {
								uni.showModal({
									content: '成绩已保存，您可以立即获取推荐院校。',
									confirmColor: '#00C15D',
									success: (res) => {
										if (res.confirm) {
											
											getBksInfo('isVip').then(data=>{
												if (data.isVip) {
													scoreEntering({
														id: id,
														studentCode: '',
														examId: ''
													}).then(res => {
														if (res.data) {
															this.$pageTo(
																'/bks/volunteer/academy/index/index', {
																	activeTab: 0,
																	examAnalysisId: res
																		.data.id
																})
														}
													})
												} else {
												this.$emit('on-vip')
												}
											})
										} else if (res.cancel) {
											console.log('用户点击取消');
											this.loading = false
										}
									}
								})
							}
						})
						this.$emit('on-save')
					}
				}).catch(err => {
					uni.showToast({
						title: err.msg,
						icon: 'none'
					})
				})
			},
			subjectDefine(e) {
				this.scoreList.scoreInfos =  e.subjectList
				this.popupShow = false
			},
		}
	}
</script>

<style lang="scss" scoped>
/* pages/expert/index/expert-item/index.wxss */

.score-item{margin-top: 10rpx;border-bottom: 1px solid #EBEBF0;}
.score-item .hd{height: 84rpx;border-bottom: 1px solid #EBEBF0;}
.score-item .hd .dot{margin-right: 10rpx; width: 12rpx;height: 12rpx;border-radius: 50%;}
.bg-3480FF{background-color: #3480FF;}
.bg-FFBC44{background-color: #FFBC44;}
.score-item .bd{padding: 20rpx 0;}
.score-item .ft{height: 80rpx;border-top: 1px solid #EBEBF0;}
.score-item .ft .bksCIcon{transform:rotate(0deg); transition: transform .3s;}
.score-item .ft .bksCIcon.unfold{transform:rotate(180deg);}
.score-item .score-tag{padding: 15rpx 0;width: 230rpx;}
.score-item .score-tag .con{margin-top: 20rpx;}

.plus-class{background: none !important;}
.input-class{background: none !important;}
.minus-class{background: none !important;}

.filter-item{padding: 30rpx 10rpx 5rpx;margin-bottom: 60rpx;}
.filter-item .tit{margin-bottom: 20rpx;height: 80rpx;}
.filter-item .tag{margin: 0 20rpx 20rpx 0; width: 335rpx;
  height: 80rpx;
  background: #FFFFFF;
  border: 1px solid #EBEBF0;
  border-radius: 8rpx;
  }

.filter-item .on{
  background: #F5FAF7;
  border: 1px solid #00C15D;}
.bottom{height: 88rpx;}
.bottom-btn{position: fixed;left: 0;bottom:60rpx; width: 100%;}
.bottom-btn .colse{background-color: #fff;}
.bottom-btn .filter{background-color: #00C15D;}
.bottom-btn .btn{ width: 335rpx; height: 84rpx;border-radius: 8rpx; border:0 none !important}
.bottom-btn .btn-00C15D{margin-right: 20rpx; border: 1px solid #00C15D !important;}
  
.weui-input{width: 100rpx; text-align: center;font-size: 26rpx;}
.minus, .plus{width: 44rpx;}
</style>